/*
 * test.c
 *
 *  Created on: 2011/06/07
 *      Author: AKS
 */

#include "core/include/aks_processor.h"
#include "core/include/process.h"
#include "core/include/types.h"

#include "include/test.h"

PROCESS testProcess1 =
{
	testTask1,
    NULL,
    testTask1_wakeUp,
    NULL,
    0
};

PROCESS testProcess2 =
{
	testTask2,
    NULL,
    testTask2_wakeUp,
    NULL,
    0
};

PROCESS testProcess3 =
{
    testTask3,
    NULL,
    testTask3_wakeUp,
    NULL,
    0
};


LIST_ITEM testItm1
=
{
    NULL,
    &testProcess1
};

LIST_ITEM testItm2
=
{
    NULL,
    &testProcess2
};

LIST_ITEM testItm3
=
{
    NULL,
    &testProcess3
};

BYTE task3Flag = 0x00;

void testTask1(void *param)
{
	UART_transmitString(UART_DBG, (BYTE *)"Task1 is activated. 2sec is passed. \r\n");

	sleepCurrentProcess(testTask1_wakeUp, NULL);
}

volatile WORD nextTick1 = 2000;
BOOL testTask1_wakeUp(void *param)
{
	if(nextTick1 < TIMER_systemTick())
    {
	    nextTick1 = TIMER_systemTick() + 2000;
	    task3Flag |= 0x01;
	    return TRUE;
    }
	else
	{
	    return FALSE;
	}
}

void testTask2(void *param)
{
	UART_transmitString(UART_DBG, (BYTE *)"Task2 is activated. 5sec is passed. \r\n");

	sleepCurrentProcess(testTask2_wakeUp, NULL);
}

WORD nextTick2 = 5000;
BOOL testTask2_wakeUp(void *param)
{
	if(nextTick2 < TIMER_systemTick())
    {
		nextTick2 = TIMER_systemTick() + 5000;
	    task3Flag |= 0x02;
	    return TRUE;
    }
	else
	{
	    return FALSE;
	}
}

void testTask3(void *param)
{
	UART_transmitString(UART_DBG, (BYTE *)"Task3 is activated. Task1 and Task2 is activated. \r\n");
	task3Flag = 0x00;

	sleepCurrentProcess(testTask3_wakeUp, NULL);
}


BOOL testTask3_wakeUp(void *param)
{
    if(task3Flag == 0x03)
    {
         return TRUE;
    }
    else
    {
    	return FALSE;
    }
}
